248A - Cupboards - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n=int(input())
u=[]
v=[]
for i in range(n):
    l,m=map(int,input().split())
    u.append(l)
    v.append(m)
cnt=0
cnt1=0
cnt2=0
cnt3=0
sum=0
for i in u:
    if i==0:
        cnt+=1
    else:
        cnt1+=1
sum=min(cnt,cnt1)
for i in v:
    if i==0:
        cnt2+=1
    else:
        cnt3+=1
c=sum+min(cnt2,cnt3)
print(c)

C++ Code:

#include <iostream>
using namespace std;

int main() {
   int n, cntl1 = 0, cntl2 = 0, cntr1 = 0, cntr2 = 0;
   cin >> n;
   int l[n], r[n];
   for (int i = 0; i < n; i++){
        cin >> l[i] >> r[i];
        if (l[i] == 0){
                cntl1++;
        }
        else if (l[i] == 1){
                cntl2++;
        }
        if (r[i] == 0){
                cntr1++;
        }
        else if (r[i] == 1){
                cntr2++;
        }
   }
   cout << min(cntl1, cntl2) + min(cntr1, cntr2);
   
	return 0;
}


Comments

Submit
0 Comments
More Questions

1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch
156C - Cipher
545D - Queue
459B - Pashmak and Flowers
1538A - Stone Game
1454C - Sequence Transformation